home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / buildUVSetMenu.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.7 KB  |  189 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. global proc buildUVSetMenuNames( string $menuNames[] )
  18. {
  19.     // Builds the menuNames string array from the UV sets of
  20.     // all selected objects
  21.     // The menuNames are in the format:
  22.     //  <path to object> | <uvset name>
  23.  
  24.     clear $menuNames;
  25.  
  26.     string $selectObj[] = `ls -o -sl`;
  27.     int $numObjects = size($selectObj);
  28.     int $curr = 0;
  29.  
  30.     // For each object, query its uvsets and add an entry
  31.     // for each uv set
  32.     //
  33.     for ($i=0; $i<$numObjects; $i++)    
  34.     {
  35.         string $uvSets[] = `polyUVSet -q -auv $selectObj[$i]`;
  36.         int $numUVSets = size($uvSets);
  37.         for( $j = 0; $j < $numUVSets; $j ++ ) {
  38.             $menuNames[$curr] = ($selectObj[$i] + " | " + $uvSets[$j]);
  39.             $curr ++;
  40.         }
  41.     }
  42. }
  43.  
  44. global proc buildUVSetMenu( string $parentMenu, 
  45.             string $menuNames[],
  46.             string $prefix,
  47.             int    $hasStaticItems )
  48. {
  49.     if(!$hasStaticItems) {
  50.         // Menu does not have static items, so remove all the items
  51.         menu -e -deleteAllItems $parentMenu;
  52.     } else {    
  53.         // Remove all the menu items except the last one.
  54.         // NOTE: The last item could have the option box. In this case we have to preserve 2 items.
  55.         
  56.         string $items[] = `menu -q -itemArray $parentMenu`;
  57.         int $itemCount = size($items);
  58.         int $i;
  59.  
  60.         if($itemCount > 0) {
  61.             int $isOptionBox = `menuItem -q -isOptionBox $items[$itemCount-1]`;
  62.             int $itemsToPreserve = $isOptionBox ? 2 : 1;
  63.  
  64.             for ($i=0; $i<$itemCount-$itemsToPreserve; $i++) {
  65.                 deleteUI -menuItem $items[$i];
  66.             }
  67.         }
  68.     }
  69.         
  70.     setParent -m $parentMenu;
  71.     int $numUVSets = size($menuNames);
  72.  
  73.     // If there are no UV sets to display, then put an empty menu item
  74.     if( $numUVSets == 0 ) {
  75.         menuItem -ecr false -enable false -l "No object selected." -insertAfter "";        
  76.         return;
  77.     }
  78.  
  79.     string $selectObj[] = `ls -o -sl`;
  80.     int $numObjects = size($selectObj);
  81.  
  82.     for ($i=$numUVSets-1; $i>=0; $i--)    
  83.     {
  84.         // $menuNames[$i] comes in the format
  85.         // "|polySurface3|polySurfaceShape3 | map3"
  86.         // So tokenize it on the space to get the map set name
  87.         // Then $buf[0] is the path to the uvset
  88.         // And $buf[size($buf)=1] is the uvset name
  89.         //
  90.         string $buf[];
  91.         tokenize $menuNames[$i] " " $buf;
  92.  
  93.         string $fullMenuItemName;
  94.         // Create a menu item for each uv set 
  95.         string $currUVSet[] = `polyUVSet -q -currentUVSet $buf[0]`;
  96.         if ($currUVSet[0] == $buf[size($buf) - 1]) {
  97.  
  98.             // Put a check mark on the menu item with the current uvset
  99.             $fullMenuItemName = 
  100.                 `menuItem -ecr false -l $menuNames[$i]
  101.                 -checkBox true
  102.                 -insertAfter ""
  103.                 -annotation "Copy the selected face's UVs from the active UVset to the specified UVset."
  104.                 ($prefix+$parentMenu+$i)`;        
  105.  
  106.         } else {
  107.             $fullMenuItemName = 
  108.                 `menuItem -ecr false -l $menuNames[$i]
  109.                 -insertAfter ""
  110.                 -annotation "Copy the selected face's UVs from the active UVset to the specified UVset."
  111.                 ($prefix+$parentMenu+$i)`;        
  112.         }
  113.     
  114.         // Display a shorter name in the menu item if there's
  115.         // only one object selected
  116.         if( `menuItem -exists $fullMenuItemName` && ($numObjects == 1) ) {
  117.             menuItem -e -l $buf[size($buf)-1] $fullMenuItemName;
  118.         }
  119.     
  120.     }
  121. }
  122.  
  123. global proc buildUVSetMenuWithSetUVSetCmdByIndex( 
  124.         string $parentMenu, string $whichPanel )
  125. {
  126.     // For each menu item in the given menu, attach a command
  127.     // to switch the current UV set by index, eg. 0 is the 1st map, 1 is the 2nd
  128.     //
  129.     string $menuItems[];
  130.     $menuItems = `menu -q -itemArray $parentMenu`;
  131.     int $num = size($menuItems);
  132.     int $i;
  133.     for( $i=0; $i<$num; $i++ ) {
  134.         if( `menuItem -q -enable $menuItems[$i]` ) {
  135.             string $cmd = ("textureWindow -e -suv " + $i + " " + 
  136.                             $whichPanel + ";");
  137.             // Attach a command to this menu item
  138.             menuItem -e -command $cmd $menuItems[$i];
  139.         }
  140.     }
  141. }
  142.  
  143. global proc buildUVSetMenuWithCopyUVsCmd( 
  144.         string $parentMenu, 
  145.         string $menuNames[] )
  146. {
  147.     setParent -m $parentMenu;
  148.     string $menuItems[] = `menu -q -itemArray $parentMenu`;
  149.     int $numUVSets = size($menuNames);
  150.  
  151.     // If there aren't any uv sets to display, then just return now.
  152.     if( $numUVSets == 0 ) {
  153.         return;
  154.     }
  155.  
  156.     int $i;
  157.     for( $i=0; $i<$numUVSets; $i++ ) 
  158.     {
  159.         string $buf[];
  160.         tokenize $menuNames[$i] " " $buf;
  161.         
  162.         if( size($buf) == 0 ) continue;
  163.  
  164.         // for each menu item, disable it if it's the active one
  165.         // or add a command to run the polyCopyUVs cmd
  166.         string $currUVSet[] = `polyUVSet -q -currentUVSet $buf[0]`;
  167.         string $destinationUVSet = $buf[size($buf) - 1];
  168.  
  169.         if ($currUVSet[0] == $destinationUVSet)
  170.         {
  171.             menuItem -e -enable false $menuItems[$i];
  172.         } else {
  173.  
  174.             //  Overwrite the existing command with a polyCopyUVs cmd
  175.             string $setCurrentUVSetCmd = 
  176.                 ("polyUVSet -currentUVSet -uvSet " + $destinationUVSet + " ;");
  177.             string $copyCmd = ( 
  178.                     "if( `performPolyCopyUVsToUVset " 
  179.                     + $currUVSet[0] + "  " 
  180.                     + $destinationUVSet 
  181.                     + " ` > 0 ) { " 
  182.                     + $setCurrentUVSetCmd 
  183.                     + "}"
  184.                     );
  185.             menuItem -e -command $copyCmd $menuItems[$i];
  186.         }
  187.     }
  188. }
  189.